<template>
  <div id="LabApplyItem">
    <Breadcrumb content="病人来源指标" />
    <div class="bodyContent">
      <vxe-toolbar perfect>
        <template #buttons>
          <vxe-button type="text" class="button-blue" icon="vxe-icon-save" content="保存" :loading="showLoading" @click="save"></vxe-button>
        </template>
      </vxe-toolbar>
      <div class="leftTable">
        <vxe-table ref="labFeeItemTable" border class="mytable-scrollbar" height="auto" :scroll-y="{ enabled:true }" resizable show-header-overflow show-overflow align="left" :row-config="{ isCurrent: true, isHover: true }"  :data="patTypeList" :loading="showLoading">
          <vxe-column field="code" title="编码" ></vxe-column>
          <vxe-column field="name" title="病人来源" ></vxe-column>
          <vxe-column field="openWith" title="指标类型" :edit-render="{ autofocus: '.vxe-input--inner' }" align="center" width="120">
            <template #default="{ row }">
              <el-select v-model="row.qiType" filterable>
                <el-option v-for="tkms in qiTypeList" :key="tkms.id" :label="tkms.name" :value="tkms.code"></el-option>
              </el-select>
            </template>
          </vxe-column>
        </vxe-table>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
// 引入组件区 ==========
import Breadcrumb from '@/components/Breadcrumb.vue';
import { ref, reactive, getCurrentInstance, onMounted } from 'vue';
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage'; //提示信息
import { AppStore } from "@/stores/store";

// 全局变量定义区 ==========
// 变量定义区
let { proxy }: any = getCurrentInstance();
let store = AppStore();

let conWidth = ref(document.documentElement.clientWidth);
let patTypeList = reactive([]);
let qiTypeList = reactive([]);
let showLoading = ref(false); //刷新+表格加载
let saveLoading = ref(false); //保存
let form = reactive({}); //右侧基本信息表单
let searchValue = ref('');
let defaultProps = {
  children: 'children',
  label: 'name'
};


// 方法定义区 =============
onMounted(() => {
  getPatTypeList();
  getDictqiTypeList();
});


function getDictqiTypeList() {
  qiTypeList.length = 0;
  const url = '/api/sys/basDictDetail/findDictDetailList';
  proxy.$http
      .get(url, { params: { code: 'qiType' } })
      .then((res: any) => {
        qiTypeList.push(...res.data);
      })
      .catch((err: any) => {
        proxy.$alert(err, '提示');
      });
}
// 获取病人类型列表
function getPatTypeList() {
  patTypeList.length = 0;
  showLoading.value = true;
  const url = '/api/qi/patType/getPatTypeList';

  proxy.$http
      .get(url)
      .then((res: any) => {
        patTypeList.push(...res.data);
        showLoading.value = false;
      })
      .catch((err: any) => {
        proxy.$alert(err, '提示');
        showLoading.value = false;
      });
}

// 保存
function save() {
  let dataList=[];
  for (const item of patTypeList) {
    const data ={
      patType:item.code,
      qiType:item.qiType
    };
    dataList.push(data)
  }
  let url = '/api/qi/patType/addPatType';
  proxy.$http
      .post(url, dataList)
      .then((res: any) => {
        VxeMessage(res.status.msg, VxeNotifyType.success);
      })
      .catch((err: any) => {
        VxeMessage(err, VxeNotifyType.error);
      });
}

</script>
<style lang="scss" scoped>
#LabApplyItem {
  height: 100%;

  .bodyContent {
    height: calc(100% - 60px);
    // 附加按钮间距
    .button-blue,
    .button-red {
      margin: 5px 0 5px 5px;
    }
    .leftTable {
      height: calc(100% - 40px);
    }
  }
}
</style>
